package com.kangfawei.io.utils;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class FileUtils {

    /**
     * 对接输入输出流：文件拷贝
     * @param is
     * @param os
     */
    public void copy(InputStream is, OutputStream os) throws IOException{
        byte[] flush = new byte[1024];
        int length = 0;
        while((length = is.read(flush)) != -1){
            os.write(flush,0,length);
        }
        os.flush();
    }

    /**
     * 释放资源1
     * @param is
     * @param os
     * @throws IOException
     */
    public void close(InputStream is,OutputStream os) throws IOException{
        if(null != is){
            is.close();
        }
        if(null != os){
            os.close();
        }
    }

    /**
     * 释放资源
     * @param ios
     * @throws IOException
     */
    public void close(Closeable... ios) throws IOException{
        for (Closeable io : ios) {
            if(null != io){
                io.close();
            }
        }
    }
}
